<?php


namespace App\Http\Server;


use App\Models\WheatPrice;

class WheatPriceServer
{
    public function addWheatPriceServer($id,$now_date,$cost_price,$sales_price){
        if(isset($id) && !empty($id)){
            $model = WheatPrice::find($id);
        }else{
            $model = new WheatPrice();
        }

        $model->now_date = $now_date;
        $model->cost_price = $cost_price;
        $model->sales_price = $sales_price;
        $model->profit = $sales_price-$cost_price;
        $model->save();
        return ['status'=>200,'data'=>$model,'msg'=>'success'];
    }


    public function getWheatPriceListServer($params,$per_page=10)
    {
        // 执行查询
        $users = WheatPrice::Search($params)->orderBy('now_date','desc')->paginate($per_page)->toArray();
        return ['status'=>200,'data'=>$users['data'],'msg'=>'success'];
    }

    public function getWheatPriceNewServer()
    {
        $info = WheatPrice::orderBy('now_date','desc')->first();
        return ['status'=>200,'data'=>$info,'msg'=>'success'];
    }
}
